package com.zhongyi;

import com.zhongyi.dao.IUserAliaDao;
import com.zhongyi.domain.UserAlia;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class Mybatis_alia {
    private InputStream in = null;
    private SqlSession sqlSession = null;
    private IUserAliaDao dao = null;

    @Before
    public void init(){
        try {
            in = Resources.getResourceAsStream("SqlMapConfig.xml");
            SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(in);
            sqlSession = sessionFactory.openSession();
            dao = sqlSession.getMapper(IUserAliaDao.class);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @After
    public void destory() throws IOException {
        sqlSession.commit();
        sqlSession.close();
        in.close();
    }

    @Test
    public void testFindAll(){
        List<UserAlia> list = dao.findAll();
        for(UserAlia userAlia:list){
            System.out.println(userAlia);
        }
    }
}
